home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / ste / autoexec.lzh / SOURCE / LOADSEGM.C < prev    next >
C/C++ Source or Header  |  1991-08-05  |  1KB  |  53 lines

  1. #include <tos.h>
  2.  
  3.  
  4. typedef struct
  5.     {    long magic;
  6.         long freq;
  7.         int  r_seg;
  8.     }    SEGM_HEADER;
  9.     
  10. const long IdentFreq[]  = {'6.25', '12.5', '25.0', '50.0'};
  11.  
  12. /* the DMA play back frequency */
  13. extern int PlayFreq;
  14.  
  15.  
  16.  
  17. int LoadSegm(int f, int *rep_segm, long length, long *segm)
  18. {long *s, freq;
  19.  char *image;
  20.  SEGM_HEADER head;
  21.  
  22.      Fread(f, sizeof(SEGM_HEADER), &head); /* read the header */
  23.      if (head.magic != 'SEGM')
  24.          return 3;
  25.  
  26.     s = IdentFreq;  /* get playback frequency from file */
  27.     freq = 0;
  28.     while(*s++ != head.freq)
  29.         if (freq++ > 4)
  30.             return 2;
  31.         
  32.     PlayFreq    = 128 + (int)freq;
  33.     
  34.     *rep_segm = head.r_seg; /* get repeat segment from file */
  35.  
  36.     Fread(f, length, segm); /* read file into memory */
  37.     
  38. /* find address of the sample image */
  39.     s = segm; 
  40.     while (*s != -1)
  41.         s += 2;
  42.         
  43.     image = (char *)(s + 2);
  44.     
  45. /* Now fixup the sequence table, (offsets -> abs. addreses) */
  46.     while (*segm != -1)
  47.     {    *segm = (long)(image + *segm);
  48.         segm += 2;
  49.     }
  50.     
  51.     return 0;
  52. }
  53.